package com.example.helloandroid;

import java.util.ArrayList;

import android.R.integer;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

	TextView showTextView;
//	ArrayList<Button> btn;
	public Button[] btn;
	public int pre;
	public int text;
	public int btnText;
	int i;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		btn					= new Button[12];
		
		setContentView(R.layout.activity_main);
		showTextView = (TextView)findViewById(R.id.showText);
		
		for(i = 0; i < 12; ++i){
			Integer test = R.id.button1 + i;
			btn[i] = ((Button)findViewById(test));
			String getstr = btn[i].getText().toString();
			btnText = getstr.codePointAt(0);
		}
		
		btn[0].setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				text = (text * 10) + 1;
				CharSequence cs = "test";
				Integer test = new Integer(text);
				cs = test.toString();
				showTextView.setText(cs);
//				btnText = ((String)(btn[0].getText())).codePointAt(0);
				// TODO Auto-generated method stub
//				if(btnText == 43){			// +
//				text = pre;
//				text = 0;
//				}
//				else if(btnText == 61){		// =
//					text += pre;
//				}
//				else{
//					text 			= (text * 10) + (btnText%47);
//				}
			}
		});
		
		btn[1].setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				text = (text * 10) + 2;
				CharSequence cs = "test";
				Integer test = new Integer(text);
				cs = test.toString();
				showTextView.setText(cs);
				
			}
		});
		
		btn[2].setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				text = (text * 10) + 3;
				// TODO Auto-generated method stub
				CharSequence cs = "test";
				Integer test = new Integer(text);
				cs = test.toString();
				showTextView.setText(cs);
				
			}
		});
		
		btn[3].setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				text = (text * 10) + 4;
				// TODO Auto-generated method stub
				CharSequence cs = "test";
				Integer test = new Integer(text);
				cs = test.toString();
				showTextView.setText(cs);
				
			}
		});
		
		btn[4].setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				text = (text * 10) + 5;
				// TODO Auto-generated method stub
				CharSequence cs = "test";
				Integer test = new Integer(text);
				cs = test.toString();
				showTextView.setText(cs);
				
			}
		});
		
		btn[5].setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				text = (text * 10) + 6;
				// TODO Auto-generated method stub
				CharSequence cs = "test";
				Integer test = new Integer(text);
				cs = test.toString();
				showTextView.setText(cs);
				
			}
		});
		
		btn[6].setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				text = (text * 10) + 7;
				// TODO Auto-generated method stub
				CharSequence cs = "test";
				Integer test = new Integer(text);
				cs = test.toString();
				showTextView.setText(cs);
				
			}
		});
		
		btn[7].setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				text = (text * 10) + 8;
				// TODO Auto-generated method stub
				CharSequence cs = "test";
				Integer test = new Integer(text);
				cs = test.toString();
				showTextView.setText(cs);
				
			}
		});
		
		btn[8].setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				text = (text * 10) + 9;
				// TODO Auto-generated method stub
				CharSequence cs = "test";
				Integer test = new Integer(text);
				cs = test.toString();
				showTextView.setText(cs);
				
			}
		});
		
		btn[9].setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				pre = text;
				text = 0;
				CharSequence cs = "test";
				Integer test = new Integer(text);
				cs = test.toString();
				showTextView.setText(cs);
				
			}
		});
		
		btn[10].setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				text *= 10;
				CharSequence cs = "test";
				Integer test = new Integer(text);
				cs = test.toString();
				showTextView.setText(cs);
				
			}
		});
		
		btn[11].setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				text += pre;
				CharSequence cs = "test";
				Integer test = new Integer(text);
				cs = test.toString();
				showTextView.setText(cs);
				
			}
		});
		
//		for(i = 0; i < 12; ++i){
//			Integer test = R.id.button1 + i;
//			btn[i] = ((Button)findViewById(test));
////			cl.onClick(btn[i]);
////			showTextView.setText(btn[i].getText());
//			btn[i].setOnClickListener(new View.OnClickListener() {
//				Integer btnText = ((String)(btn[i].getText())).codePointAt(0);
//				
//				@Override
//				public void onClick(View v) {
//					// TODO Auto-generated method stub
//					if(btnText == 43){			// +
//						text = pre;
//						text = 0;
//					}
//					else if(btnText == 61){		// =
//						text += pre;
//					}
//					else{
//						text 			= text * 10 + btnText;
//					}
//					
//				}
//			});
//		}
//		showTextView.setText(text.toString());
		
//		Integer test = new Integer(R.id.button1);
//		showTextView.setText(test.toString());
		
//		Button btn = (Button)findViewById(R.id.copyTextButton);
//		btn.setOnClickListener(new View.OnClickListener() {
//			
//			@Override
//			public void onClick(View v) {
//				showTextView.setText(inputTextView.getText().toString());
//				
//				
//			}
//		});
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
